from django.shortcuts import render
from rest_framework.views import APIView
from .serializers import CartSerializer

# Create your views here.
class CartView(APIView):
    """购物车增删改查"""

    def perform_authentication(self, request):
        """重写此方法 直接pass  可以延后认证"""
        pass

    def post(self, request):
        """新增"""
        serializer = CartSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        sku_id = serializer.validated_data.get('sku_id')
        count = serializer.validated_data.get('count')
        selected = serializer.validated_data.get('selected')

        try:
            user = request.user#执行此代码会执行认证逻辑，如果登录用户认证会成功无异常，但是未登录用户认证会出异常自己拦截
        except:
            user = None
        if user and user.is_authenticated:
            """登录用户 操作redis"""
        else:
            """未登录用户 操作cookie"""
        pass

    def get(self, request):
        """查询"""
        pass

    def put(self, request):
        """修改"""
        pass

    def delete(self, request):
        """删除"""
        pass
